#include<iostream.h>
#include"iomanip.h"
#include"radioson.h"
//class implenetation
RadioSonde::RadioSonde()
{
//no array is used here!
code="XD153-A";
speed=0;
direction=0;
readSeaMax=0;
readSeaMin=0;
}
//the sea level data are recorded every 5 minutes
//and the report is transmitted every 25 minutes
void RadioSonde::recordSeaLevel()
{
double seaLevel;
int timeInMinutes=5;
while(timeInMinutes<=25)
{
cout<<" At Time("<<timeInMinutes
<<") sea Level read in meters: ";
cin>>seaLevel;
if(timeInMinutes==5)
{
readSeaMax=seaLevel;
readSeaMin=seaLevel;
}
if(seaLevel>readSeaMax)
{
readSeaMax=seaLevel;
}
if(seaLevel<readSeaMin)
{
readSeaMin=seaLevel;
}
timeInMinutes=timeInMinutes+5;
}
cout<<endl;
}
void RadioSonde::windSensor()
{
double windSpeed,windTheta,sumX=0,sumY=0,count=0;
int timeInMinutes=1;
while(timeInMinutes<=5)
{
cout<<" At Time("<<timeInMinutes*5
<<") wind sensor recorded follwoing speed and direction: ";
cin>>windSpeed>>windTheta;
speed=windSpeed;
direction=windTheta;
sumX+=(speed*cos(direction));
sumY+=(speed*sin(direction));
timeInMinutes++;
count++;
}
cout<<endl;
//average speed and angle are computed here, while receiving report,
//since this class need an array for storage mechanism.
aveSpeed=(sqrt((((sumX/count)*(sumX/count))+((sumY/count)*(sumY/count)))));
aveTheta=(atan2((sumY/count),(sumX/count)))*(180/PI);
}
void RadioSonde::intialSetting()
{
//class attributes are reset here
speed=0;
direction=0;
readSeaMax=0;
readSeaMin=0;
}
void RadioSonde::writeReport()
{
cout<<endl;
cout<<endl;
cout<<" RadioSonde "<<code<<" report:"<<endl;
cout<<" Minimum sea-level: "<<setreal(1,1)
<<readSeaMin<<" m"<<endl;
cout<<" Maximum sea-level: "<<setreal(1,1)
<<readSeaMax<<" m"<<endl;
cout<<" Average wind speed: "<<setreal(1,1)
<<" "<<aveSpeed<<" m/s"<<endl;
cout<<" Average wind direction: "<<setreal(1,0)
<<aveTheta<<" degrees"<<endl;
cout<<endl;
cout<<endl;
intialSetting();
}
int main()
{
RadioSonde seaConditions;//seaConditions object is created and it is invoking
//given member fcn.
seaConditions.recordSeaLevel();
seaConditions.windSensor();
seaConditions.writeReport();
return 0;
}
/*
Run:
At Time(5) sea Level read in meters: 301.2
At Time(10) sea Level read in meters: 302.1
At Time(15) sea Level read in meters: 305.4
At Time(20) sea Level read in meters: 302.4
At Time(25) sea Level read in meters: 303
At Time(5) wind sensor recorded follwoing speed and direction: 1 1
At Time(10) wind sensor recorded follwoing speed and direction: 1.4 1.8
At Time(15) wind sensor recorded follwoing speed and direction: 2.4 2
At Time(20) wind sensor recorded follwoing speed and direction: 5.6 1
At Time(25) wind sensor recorded follwoing speed and direction: 4.9 0.98
RadioSonde XD153-A report:
Minimum sea-level: 301.2 m
Maximum sea-level: 305.4 m
Average wind speed: 2.8 m/s
Average wind direction: 69 degrees
Press any key to continue
*/
|